#include "cw_brighness_config.h"
CW_BRIGHNESS cw_date_config;

void set_cw_config_w(u8 W)
{
    cw_date_config.w =W;
}

u8 get_cw_config_w()
{
    return cw_date_config.w;
}

u8 get_cw_config_cw()
{
    return MAX_BRIGHT-cw_date_config.w;
}


void init_cw_level(u8 level,u8 brighness)
{
    if (level <MIN_BRIGH)
    {
        cw_date_config.w =MIN_BRIGH;
        cw_date_config.cw = MAX_BRIGHT;
    }
    else if(level>MAX_BRIGHT)
    {
       cw_date_config.w =MAX_BRIGHT;
       cw_date_config.cw = MIN_BRIGH;
    }
    else
    {   
        cw_date_config.w=level;
        cw_date_config.cw = MAX_BRIGHT-level;
    }

    if (brighness <MIN_BRIGH)
    {
        cw_date_config.brighness =MIN_BRIGH;
    }
    else if(brighness>MAX_BRIGHT)
    {
       cw_date_config.brighness =MAX_BRIGHT;
    }
    else
    {   
        cw_date_config.brighness=brighness;
    }

    LOG_INFO("brighness is %d,level is%d\n",cw_date_config.brighness,cw_date_config.w);
}




u8 get_cw_config_brighness()
{
    return cw_date_config.brighness;
}

void set_cw_config_brighness(u8 brighness)
{
    if (brighness <MIN_BRIGH)
    {
        cw_date_config.brighness =MIN_BRIGH;
    }
    else if(brighness>MAX_BRIGHT)
    {
        cw_date_config.brighness=MAX_BRIGHT;
    }
    else
    {   
        cw_date_config.brighness=brighness;
    }
    LOG_INFO("brighness_level is%d\n",brighness);
}

void reduce_cw_brighness(u8 brighness)
{
    if (cw_date_config.brighness<brighness)//最小不能小于0
    {
       cw_date_config.w=0; 
    }
    else 
    {
        cw_date_config.brighness =cw_date_config.brighness-brighness;
    }
    LOG_INFO("cw_brighness is%d\n",cw_date_config.w);
}

void add_cw_brighness(u8 brighness)
{
    if(cw_date_config.brighness+brighness>MAX_BRIGHT)
    {
        cw_date_config.brighness=MAX_BRIGHT;
    }
    else
    {
        cw_date_config.brighness = cw_date_config.brighness+brighness;
    }
    LOG_INFO("cw_brighness is%d\n",cw_date_config.brighness);
}

void reduce_cw_level(u8 reduce_level)  //降低灯管亮度
{
    if (cw_date_config.w<reduce_level)//最小不能小于0
    {
       cw_date_config.w=0; 
    }
    else 
    {
        cw_date_config.w =cw_date_config.w-reduce_level;
    }
    LOG_INFO("cw_level is%d\n",cw_date_config.w);
}

void add_cw_level(u8 add_level)//增加灯光亮度
{
    if(cw_date_config.w+add_level>MAX_BRIGHT)
    {
        cw_date_config.w=MAX_BRIGHT;
    }
    else
    {
        cw_date_config.w = cw_date_config.w+add_level;
    }
    LOG_INFO("cw_level is%d\n",cw_date_config.w);
}

void once_cw_brilliance_handle(SYS_OPT_KEY opt)
{
    if(OPT_GO_ADD==opt.oepation)
    {
        add_cw_brighness(LIGHT_CONTINUE);
    }
    else if(OPT_GO_ADD_CONTINUE==opt.oepation)
    {
        add_cw_brighness(LIGHT_LEVEL);
    }
    else if(OPT_GO_REDUCE==opt.oepation)
    {
        reduce_cw_brighness(LIGHT_CONTINUE);
    }
        else if(OPT_GO_REDUCE_CONTINUE==opt.oepation)
    {
        reduce_cw_brighness(LIGHT_LEVEL);
    }
}


void cw_brilliance_control_handle(SYS_OPT_KEY opt)
{
    once_cw_brilliance_handle(opt);
}